// 1=》h5 2=》h5微信 3=》微信小程序
export default function (sync = false): number | Promise<number> {
  const enum ENVTYPE { other, h5, wx, wxapp }
  let ua: string = window.navigator.userAgent.toLowerCase()
  let sign = window ? ENVTYPE.h5 : ENVTYPE.other

  if (sign !== ENVTYPE.other && /MicroMessenger/i.test(ua)) {
    wx.miniProgram.getEnv((res: any) => {
      sign = res.miniprogram ? ENVTYPE.wxapp : ENVTYPE.wx
    })
  }
  if (sync) {
    return sign
  } else {
    return Promise.resolve(sign)
  }
}
